<template>
	
	<view>
<view class="top"><uni-search-bar class="sbg" bgColor="#FFFFFF" @confirm="so" :radius="100"></uni-search-bar>
</view><view class="top-pd"></view>
<view class="b p10 bl"><text class="red">{{q}}</text>的搜索结果</view>
	<block v-if="data.length>0">
	<block v-for="(newsitem,index2) in data" :key="index2">
	<media-item :newitem="newsitem" :q="q"></media-item>
	<yad v-if="index2 %8==4" mode="feed"></yad>
	</block>
	</block>
<block v-else>
<view class="b p10 c">No record<br>无记录</view>
</block>
<pagestatus v-if="status.code !=408" :status="status"
	v-on:btnclick="getdata"
	></pagestatus>
<view v-else class="b p10 c">END<br>全部加载完毕</view>
</view>
</template>

<script>
	var __self=false;/*this的优化 */
	var  pageid=0
	import mediaItem from '@/components/list.vue';
	import yad from '@/components/yad.vue'
	import pagestatus from '@/components/page-status.vue'
export default {
components: {
mediaItem,yad,pagestatus
},
data() {
return {
data:[],
q:'关键字',
status:{
loading:true,
icon:'content',
title:'页面加载中...',
desc:'长时间无反应请点重新加载',
showBtn:true,
btnText:'重新加载',
code:400
}
}
},onLoad(i) {
    pageid=0
if(i.q) this.q=decodeURIComponent(i.q)
__self=this;
this.getdata()
},onShareAppMessage() {
    return {
        title: getApp().globalData.ysv8set.title,
        content: getApp().globalData.ysv8set.description,
        path: 'pages/index/index',
        imageUrl: getApp().globalData.ysv8set.img
    }
},onReachBottom: function() {
   if(this.status.code !=408) this.getdata()
},methods: {
so(k){
    uni.navigateTo({url: '/pageb/s/index?q='+encodeURIComponent(k.value)});
},getdata(){
uni.request({method:"GET",
cloudCache:getApp().globalData.ysv8set.cloudCache,
url:getApp().globalData.ysv8set.www+"s/index/"+encodeURIComponent(this.q)+"/"+pageid+".api",data:{},
success:function(e){
if(e.statusCode ==200){
__self.data=pageid==0?e.data.data:__self.data.concat(e.data.data),
__self.status={
title:'加载完成',
showBtn:false,
code:e.data.data.length<10?408:200
}
if(e.data.data.length>0)pageid++;
}else{
 __self.status={
 title:'网络错误',
 desc:'网络连接错误',
 showBtn:true,
 btnText:'重新加载',
 code:400
  }

}

},fail:function(){
__self.status={
title:'网络错误',
desc:'网络连接错误',
showBtn:true,
btnText:'重新加载',
code:400
 }
}
});


},
	}
}
</script>

<style>
</style>
